"! Info:
Abstract number class
Examples:

"
Magnitude subclass: Number [
<category: 'Library-Numbers'>
"! "
absolute [
(self negative) ifTrue: [ 
	^ self negated 
]
]

"! Info:

Examples:
"
asChar [
^ Char new: (self asSmallInt)
]

"! "
asDigit [
(self < 10) ifTrue: [ 
	^ (Char new: (self asSmallInt + 48)) asString 
].
^ (Char new: (self asSmallInt + 55)) asString
]

"! "
atRandom [
(self < 2) ifTrue: [ 
	^ self 
].
^ (self class atRandom absolute) rem: self.
]

"! Info:

Examples:
"
bitAnd: arg [
^ (self asSmallInt bitAnd: arg)
]

"! Info:

Examples:
"
bitOr: arg [
^ (self asSmallInt bitOr: arg)
]

"! Info:

Examples:
"
bitShift: arg [
^ (self asSmallInt bitShift: arg)
]

"! Info:
Raise a divide-by-zero exception.
Examples:

"
divzero [
self error: #sysDivZero
]

"! "
factorial [
self <= 1 ifTrue: [ 
	^ 1
] ifFalse: [ 
	^ (self - 1) factorial * self 
]
]

"! "
negated [
^ 0 - self
]

"! "
negative [
^ self < 0
]

"! Info:

Examples:
"
overflow [
self error: #sysOverflow
]

"! Info:

Examples:
"
printString [
^ self printWidth: 1 base: 10
]

"! Info:

Examples:
"
printWidth: width [
^ self printWidth: width base: 10
]

"! Info:

Examples:
"
printWidth: width base: base [
| ret n dig wasNeg wide |
ret := ''.
(self negative) ifTrue: [
	wasNeg := true.
	wide := width-1.
	n := self negated
] ifFalse: [
	wasNeg := false.
	wide := width.
	n := self
].
[true] whileTrue: [
	ret := ((n rem: base) asDigit) + ret.
	n := n / base.
	(n = 0) ifTrue: [
		((ret size)+1) to: wide do: [ :i |
			ret := '0' + ret
		].
		wasNeg ifTrue: [ ret := '-' + ret ].
		^ ret
	]
]
]

"! Info:
Execute aBlock a number of times.
Examples:
4 timesRepeat: [
	'hello world' printNl.
].
"
timesRepeat: aBlock [
| i |
i := 1.
[ i <= self ] whileTrue: [ 
	aBlock value. 
	i := i + 1 
]
]

"! "
to: limit by: step do: aBlock [
| i |
i := self.
i <= limit ifTrue: [
	[ i <= limit ] whileTrue: [ 
		aBlock value: i. 
		i := i + step
	].
] ifFalse: [
	[ i >= limit ] whileTrue: [ 
		aBlock value: i. 
		i := i + step
	].
].
]

"! "
to: limit do: aBlock [
| i |
i := self.
[ i <= limit ] whileTrue: [ 
	aBlock value: i. 
	i := i + 1 
]
]

]

"! Class methods for Number "
MetaMagnitude subclass: MetaNumber [
<category: 'Library-Numbers'>
"! Info:
Cannot create new number via new, return 0

Examples:
"
new [
^ 0
]

]

